﻿<local:BaseSourceContentFrame x:Class="InfFront.InfoViews.WPF.ListWithToolbarFrame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InfFront.InfoViews.WPF"
    Height="Auto" Width="Auto" MinWidth="300" MinHeight="300"
    >

    <UserControl.Resources>
        <local:IconedObjectToNormal24x24ImageConverter x:Key="getNormalButtonImage"/>
        <local:EqualityCheckToBoolConverter x:Key="ifEquals"/>
        
        <local:ListWithToolbarFrameStyle x:Key="frameStyleGrid">Grid</local:ListWithToolbarFrameStyle>
        <local:ListWithToolbarFrameStyle x:Key="frameStylePlot">Plot</local:ListWithToolbarFrameStyle>
        <local:ListWithToolbarFrameStyle x:Key="frameStyleIcons">Icons</local:ListWithToolbarFrameStyle>

        <Style x:Key="defaultListStyleMenuItem" TargetType="{x:Type MenuItem}">
            <Setter Property="IsCheckable" Value="True"/>
            <EventSetter Event="Click" Handler="ListStyleMenuItem_Clicked"/>
        </Style>
    </UserControl.Resources>

    <UserControl.ContextMenu>
        <ContextMenu Name="contextMenu">
            <MenuItem Name="viewAsSubmenu"  Header="View as...">
                <MenuItem Header="Detailed list" Style="{StaticResource defaultListStyleMenuItem}"
                          Tag="{StaticResource frameStyleGrid}">
                    <MenuItem.IsChecked>
                        <Binding Path="VisualSettings.ListWithToolbarFrameStyle" Mode="OneWay" 
                                 Converter="{StaticResource ifEquals}" ConverterParameter="{StaticResource frameStyleGrid}"/>
                    </MenuItem.IsChecked>
                </MenuItem>
                <MenuItem Header="Icons" Style="{StaticResource defaultListStyleMenuItem}"
                          Tag="{StaticResource frameStyleIcons}">
                    <MenuItem.IsChecked>
                        <Binding Path="VisualSettings.ListWithToolbarFrameStyle" Mode="OneWay" 
                                 Converter="{StaticResource ifEquals}" ConverterParameter="{StaticResource frameStyleIcons}"/>
                    </MenuItem.IsChecked>
                </MenuItem>
                <MenuItem Header="Plot" Style="{StaticResource defaultListStyleMenuItem}"
                          Tag="{StaticResource frameStylePlot}">
                    <MenuItem.IsChecked>
                        <Binding Path="VisualSettings.ListWithToolbarFrameStyle" Mode="OneWay" 
                                 Converter="{StaticResource ifEquals}" ConverterParameter="{StaticResource frameStylePlot}"/>
                    </MenuItem.IsChecked>
                </MenuItem>
            </MenuItem>
            
            <MenuItem Header="Preferences..." Click="PreferencesMenuItem_Click" />
        </ContextMenu>
    </UserControl.ContextMenu>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" MinHeight="50" />
            <RowDefinition MinHeight="100" />
        </Grid.RowDefinitions>

        <WrapPanel Grid.Row="0" Name="pnlCommands">
            <ItemsControl x:Name="commandsControlList" Padding="4" VerticalContentAlignment="Center">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel VerticalAlignment="Center" Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Focusable="False" Margin="4" 
                                Click="CommandButton_Click" VerticalAlignment="Center"
                                IsEnabled="{Binding Path=IsEnabled}"
                                ToolTip="{Binding Path=Comment}"
                                >
                            <Button.Background>
                                <SolidColorBrush Color="{Binding Path=VisualSettings.CommandButtonColor, FallbackValue=Azure}" />
                            </Button.Background>
                            <WrapPanel>
                                <Image Width="24" Height="24" Source="{Binding Converter={StaticResource getNormalButtonImage}}"/>
                                <TextBlock Margin="4" Text="{Binding Path=Title}" VerticalAlignment="Center" />                        
                            </WrapPanel>
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </WrapPanel>

        <ContentControl Name="content" Width="Auto" Height="Auto" Grid.Row="1" />        
    </Grid>
</local:BaseSourceContentFrame>
